package cn.acac.yygh.cmn.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;

import java.util.ArrayList;
import java.util.List;

public class ExcelTest {

    // 方式一：往单个sheet中写数据
    /*public static void main(String[] args) {
        // 使用EasyExcel进行写出操作
        // 创建虚拟数据
        List<Student> studentList = new ArrayList<>();
        studentList.add(new Student(1,"张三",1001,"安徽省安庆市"));
        studentList.add(new Student(2,"李四",1002,"安徽省合肥市"));
        studentList.add(new Student(3,"王五",1003,"安徽省阜阳市"));
        studentList.add(new Student(4,"赵六",1004,"安徽省黄山市"));
        // 第一个参数为：写出到哪
        // 第二个参数为：写出的数据
        EasyExcel.write("C:\\Users\\18034\\Desktop\\hello.xlsx",Student.class)
                .sheet("学生列表").doWrite(studentList);
    }*/

    // 方式二：往多个sheet中写数据
    public static void main(String[] args) {
        // 创建虚拟数据
        List<Student> studentList = new ArrayList<>();
        studentList.add(new Student(1,"张三",1001,"安徽省安庆市"));
        studentList.add(new Student(2,"李四",1002,"安徽省合肥市"));
        studentList.add(new Student(3,"王五",1003,"安徽省阜阳市"));
        studentList.add(new Student(4,"赵六",1004,"安徽省黄山市"));

        ExcelWriter build = EasyExcel.write("C:\\Users\\18034\\Desktop\\hello.xlsx",Student.class).build();
        WriteSheet writeSheet01 = EasyExcel.writerSheet(0, "学生列表1").build();
        WriteSheet writeSheet02 = EasyExcel.writerSheet(1, "学生列表2").build();
        // 写出第一个sheet
        build.write(studentList,writeSheet01);
        // 写出第二个sheet
        build.write(studentList,writeSheet02);
        // 关闭流
        build.finish();

    }
}
